/**
 * Created by Administrator on 2017/8/25 0025.
 */


 isSpecialFormatter = function (value, row, index) {
    if (value == 2) {
        return "申请当中";
    } else if (value == 1) {
        return "是";
    }
}

 timeFormatter = function (value, row, index) {
    if (row.isSpecial == 1) {
        return value;
    } else if (row.isSpecial == 2) {
        return "特价申请当中,无到期时间";
    }
}


var headPicFormatter = function (value, row, index) {
    var img = row.headPic;
    var imgs = img.split(",");
    var imgUrl = "";
    if (img != null && img != "") {
        imgUrl = File_Download_Url + imgs[0];
        return '<image src=' + imgUrl + ' style="width:80px;height:80px" />';
    }
    if (img == null || img == "") {
        return '<image src=' + $().AbsUrlParse("/static/images/no.png") + ' style="width:80px;height:80px" />'
    }
}

var goodsFormatter = function (value, row, index) {

    return ['<a javascript="void(0)" class="showDetail">查看商品详情</a>&nbsp;&nbsp;'+
        '<a javascript="void(0)" class="agree" style="color: #00ca6d">同意</a>&nbsp;&nbsp;' +
    '<a javascript="void(0)" class="disagree" style="color: red">拒绝</a>'
    ].join('');

}

window.goodsEvent = {
    'click .agree': function (e, value, row, index) {
        showModel("goodsSpecial-div", function () {
            $("#id").val(row.id);
        })
    },
    'click .disagree': function (e, value, row, index) {
        comment.showOperationTips("你确定拒绝吗？", function () {
            $.post($().AbsUrlParse("/web/goods/disagreeSpecial"), {
                id: row.id
            }, function (data) {
                if (data.state == true) {
                    if (data.res.code == 40000) {
                        hint("操作成功");
                        var table = $('#table');
                        table.bootstrapTable('refresh');
                    } else {
                        hint(data.res.msg);
                    }
                } else {
                    hint(data.msg);
                }
            });
        });
    },

    'click .showDetail': function (e, value, row, index) {
        showModel("show-div", function () {
            setRowToFrm("showgoodsform", row);
            //图片
            var img = row.headPic;
            var imgs = "";
            if (img != null && img != "") {
                var imgArr = img.split(",");
                for (var i = 0; i < imgArr.length; i++) {
                    if (imgArr[i] != "" || imgArr[i] != null) {
                        var imgUrl = File_Download_Url + imgArr[i];
                        imgs += '<image src=' + imgUrl + ' style="width:220px;height:220px" />';
                    }
                }
                $("#showimages").html(imgs);
            }else {
                var an = '<image src=' + $().AbsUrlParse("/static/images/no.png") + ' style="width:260px;height:210px" />';
                $("#showimages").html(an);
            }

        })
    }

}


bindClick("#okSpecial", function () {
    var isSpecial = $("#isSpecial").val();
     $("#agreeSpecial").val(isSpecial);

     if(isSpecial==""&&isSpecial==null){
         hint("请选择套餐");
         return
     }

    var form = $("#detailProForm");
    var param = form.formToArray();
    $.post($().AbsUrlParse("/web/goods/agreeSpecial"),param ,function (data) {
        if (data.state == true) {
            if (data.res.code == 40000) {
                closeModel("goodsSpecial-div");
                hint("操作成功");
                var table = $('#table');
                table.bootstrapTable('refresh');
                closeModel("goodsSpecial-div");
            } else {
                hint(data.res.msg);
            }
        } else {
            hint(data.msg);
        }
    });
});


//物价商品的搜索

//查询商品
bindClick("#goodsSelect", function () {
    var goodsName = $("input[name=goodsName1]").val();
    var url = $().AbsUrlParse("/web/goods/findSpecialGoods?goodsName=" + goodsName);
    $("#table").bootstrapTable("refresh", {url: url});
})